//
//  GCMineViewController.m
//  GoldChampion
//
//  Created by Mac on 2018/4/11.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCMineViewController.h"
#import "GCMineMenuViewController.h"
#import "GCSettingViewController.h"
#import "STScanTwoCodeController.h"
#import "STPhotoUrlImageBrowerController.h"
#import "NSBundle+STSystemTool.h"
#import "GCLocalPhotoViewController.h"
#import "GCMineInfoViewController.h"
#import "GCChaZhaoViewController.h"
#import "GCQrCodeViewController.h"
#import "GCMIneHomeViewController.h"
@interface GCMineViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@property(nonatomic, strong) UINavigationController                     *nav;

@property(nonatomic, strong) STButton                     *iconButton;
@property(nonatomic, strong) STPhotoUrlImageBrowerController                     *pickerVC;
@property(nonatomic, strong) STUrlPhotoModel                     *imageModel;
@end

@implementation GCMineViewController


#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubView];
    [self configDataSouce];
     self.nav = (id)[STLayoutViewController defaultLayout].rootViewController;
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self st_hideNavagetionbarAnimated:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self st_showNavagationbarAnimated:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.contentInset = UIEdgeInsetsZero;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    __weak typeof(self) weakSelf =  self;
    
    UIView * bannerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 192)];
    bannerView.backgroundColor = [UIColor colorWithGradientStyle:UIGradientStyleTopToBottom withFrame:bannerView.bounds andColors:@[UIColorFromRGBA(0xFA8A27),UIColorFromRGBA(0xFA1F41)]];
    [header addSubview:bannerView];
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 53, 84, 84)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:42
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"宋微微"]
                                                     image:nil];
    iconButton.centerX = UIScreenWidth / 2;
    [header addSubview:iconButton];
    [iconButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedIconButton];
    }];
    self.iconButton = iconButton;
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, iconButton.bottom + 10, UIScreenWidth, 20)
                                                     text:@"大佬"
                                                textColor:[UIColor whiteColor]
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:titleLable];
    
    CGFloat buttonWith = UIScreenWidth / 3;
    
    STMenuControl * bagua = [[STMenuControl alloc] initWithFrame:CGRectMake(0, bannerView.bottom  +5, 60, 70) imageName:@"八卦" title:@"八卦" titleColor:SecendTextColor];
    bagua.centerX = buttonWith / 2;
    [header addSubview:bagua];
    
    
    STMenuControl * xiaoxi = [[STMenuControl alloc] initWithFrame:CGRectMake(0, bannerView.bottom  +5, 60, 70) imageName:@"消息00" title:@"消息" titleColor:SecendTextColor];
    xiaoxi.centerX = buttonWith / 2 + buttonWith;
    [header addSubview:xiaoxi];
    
    
    STMenuControl * sixin = [[STMenuControl alloc] initWithFrame:CGRectMake(0, bannerView.bottom  +5, 60, 70) imageName:@"信息798" title:@"私信" titleColor:SecendTextColor];
    sixin.centerX = buttonWith / 2+ 2*buttonWith;
    [header addSubview:sixin];
    
    header.height = sixin.bottom + 25;
    self.tableView.tableHeaderView = header;
    
    [xiaoxi setOnSelctedControl:^(STMenuControl *control) {
        [weakSelf onSelctedMenuTitle:control.titleLable.text];
    }];
    [bagua setOnSelctedControl:^(STMenuControl *control) {
        [weakSelf onSelctedMenuTitle:control.titleLable.text];
    }];
    [sixin setOnSelctedControl:^(STMenuControl *control) {
        [weakSelf onSelctedMenuTitle:control.titleLable.text];
    }];
}
- (void)configDataSouce{
   self.dataSouce = @[
             [[STTableEasyModel alloc] initWithTextString:@"查找" imageName:@"查找"],
              [[STTableEasyModel alloc] initWithTextString:@"设置" imageName:@"设置red"],
              [[STTableEasyModel alloc] initWithTextString:@"本地集作品" imageName:@"书籍-1"],
              [[STTableEasyModel alloc] initWithTextString:@"扫一扫" imageName:@"扫一扫"],
             ];
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    [self onSelctedMenuTitle:model.textString];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedMenuTitle:(NSString*)title{

   

    if ([title isEqualToString:@"八卦"] || [title isEqualToString:@"消息"]||[title isEqualToString:@"私信"]) {
        [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
            [self.nav pushViewController:[GCMineMenuViewController new] animated:YES];
        }];
    }
    if ([title isEqualToString:@"查找"]) {
        [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
            [self.nav pushViewController:[GCChaZhaoViewController new] animated:YES];
        }];
        
    }
    if ([title isEqualToString:@"设置"]) {
        [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
            [self.nav pushViewController:[GCSettingViewController new] animated:YES];
        }];
        
    }
    if ([title isEqualToString:@"本地集作品"]) {
        [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
            [self.nav pushViewController:[GCLocalPhotoViewController new] animated:YES];
        }];
    }
    
    if ([title isEqualToString:@"扫一扫"]) {
        STScanTwoCodeController * vc = [[STScanTwoCodeController alloc] initWithHandle:^(NSString *result, STScanTwoCodeController *vc) {
            
        }];
        [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
            [self.nav pushViewController:vc animated:YES];
        }];
    }
}
- (void)onSelectedIconButton{
    [[STLayoutViewController defaultLayout] dismissCurrentController:YES handle:^(BOOL finished) {
        [self.nav pushViewController:[GCMIneHomeViewController new] animated:YES];
    }];
}

@end
